<?php
namespace common\services\user;

use common\models\UserLogModel;
use yii\web\UserEvent;

class UserLogService extends UserLogModel
{
    /**
     * 登录成功后记录登录日志
     * @param object $event 事件对象
     * @return bool
     */
    public static function afterLoginHandler(UserEvent $event)
    {
        $model = new UserLogModel();
        $model->setAttributes([
            'user_id' => $event->identity->id,
            'user_nickname' => $event->identity->nickname,
            'created_at' => date("Y-m-d H:i:s"),
            'updated_at' => date("Y-m-d H:i:s"),
        ]);
        $model->save(false);
        return true;
    }
}